Skip to content

c/snap: add --format json to snap tasks - #17017

Merged
Rnfudge02 merged 13 commits into
canonical:masterfrom
Rnfudge02:snap-tasks
Jun 2, 2026
Merged

c/snap: add --format json to snap tasks#17017
Rnfudge02 merged 13 commits into
canonical:masterfrom
Rnfudge02:snap-tasks

Conversation

@Rnfudge02

@Rnfudge02 Rnfudge02 commented May 4, 2026

Copy link
Copy Markdown
Contributor

This PR is the final of the async snapctl work. This PR makes snap tasks --format json so that the snap tasks command aligns with the snapctl tasks command. Only the last commit of this PR are the changes made, the first 8 belong to the move_daemon branch.

@Rnfudge02 Rnfudge02 self-assigned this May 4, 2026
@github-actions github-actions Bot added the Needs Documentation -auto- Label automatically added which indicates the change needs documentation label May 4, 2026
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

Mon May 4 22:13:11 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/25343814559

No spread failures reported

@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.07%. Comparing base (156d777) to head (4c48f84).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
cmd/snap/main.go 60.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17017      +/-   ##
==========================================
+ Coverage   78.98%   79.07%   +0.08%     
==========================================
  Files        1381     1379       -2     
  Lines      191967   192447     +480     
  Branches     2464     2464              
==========================================
+ Hits       151630   152169     +539     
+ Misses      31184    31108      -76     
- Partials     9153     9170      +17     
Flag Coverage Δ
unittests 79.07% <84.61%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@olivercalder olivercalder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpicks, otherwise LGTM!

Comment thread cmd/snap/cmd_changes.go Outdated
func() flags.Commander { return &cmdTasks{} },
changeIDMixinOptDesc.also(timeDescs),
changeIDMixinOptDesc.also(timeDescs).also(map[string]string{
"format": i18n.G("Output format (json)."),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's a spec for this, but maybe it could be this:

Suggested change
"format": i18n.G("Output format (json)."),
"format": i18n.G("Output format (supported: json)."),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--format wasn't originally in the spec, snapctl tasks adopted this to maintain compatiblity with Pebble, and snap tasks got it to reflect snapctl. Updated to match your suggestion and will ensure snapctl reflects this

Comment thread tests/main/snap-tasks/tasks.yaml Outdated
# Check that valid JSON output is produced for the change, and that it contains the expected task with the expected state.
echo "Check that 'snap tasks' lists the task for the change (and accepts the --format option)"
snap tasks --format json "$CHANGE_ID_1" | jq -e '.[0].id == "remove+comp1" and .[0].state == "done"' > /dev/null

No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing \n terminator or something? Not sure

@Rnfudge02
Rnfudge02 force-pushed the snap-tasks branch 2 times, most recently from c3f3006 to ba9d3d1 Compare May 5, 2026 13:43
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

Tue Jun 2 15:15:51 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/26773493679

Failures:

Preparing:

  • openstack:opensuse-16.0-64:
  • openstack:opensuse-16.0-64:
  • openstack:opensuse-16.0-64:

Executing:

  • openstack:opensuse-tumbleweed-selinux-64:tests/main/security-logging
  • openstack:opensuse-tumbleweed-64:tests/main/security-logging

Restoring:

  • openstack:opensuse-16.0-64:
  • openstack:opensuse-16.0-64:
  • openstack:opensuse-16.0-64:

Skipped tests from snapd-testing-skip

If you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list (without variants) of the below tests you wish to run (unskip plus test list must be valid yaml)

  • garden:ubuntu-25.10-64:tests/main/apparmor-prompting-support
  • openstack-arm:ubuntu-24.04-arm-64:tests/main/i18n
  • openstack-arm:ubuntu-24.04-arm-64:tests/main/snapctl-no-wait
  • openstack-arm:ubuntu-core-24-arm-64:tests/main/i18n
  • openstack-arm:ubuntu-core-24-arm-64:tests/main/snapctl-no-wait
  • openstack:amazon-linux-2-64:tests/main/snapctl-no-wait
  • openstack:amazon-linux-2023-64:tests/main/snapctl-no-wait
  • openstack:arch-linux-64:tests/main/snapctl-no-wait
  • openstack:centos-9-64:tests/main/snapctl-no-wait
  • openstack:debian-12-64:tests/main/snapctl-no-wait
  • openstack:debian-sid-64:tests/main/interfaces-network-status-classic
  • openstack:debian-sid-64:tests/main/snapctl-no-wait
  • openstack:fedora-44-64:tests/main/snapctl-no-wait
  • openstack:opensuse-16.0-64:tests/main/snapctl-no-wait
  • openstack:opensuse-tumbleweed-64:tests/main/snapctl-no-wait
  • openstack:opensuse-tumbleweed-selinux-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-16.04-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-18.04-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-20.04-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-22.04-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-24.04-64:tests/main/i18n
  • openstack:ubuntu-24.04-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:audio_record_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:audio_record_timespan_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:audio_record_timespan_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_multiple_actioned_by_other_pid_always_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_multiple_actioned_by_other_pid_always_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_multiple_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_multiple_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_multiple_not_actioned_by_other_pid_single_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_multiple_not_actioned_by_other_pid_single_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_write_chmod_same_fd_single_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_write_chmod_same_path_single_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:create_write_write_same_path_single_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:download_file_conflict
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:download_file_defaults
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:download_file_safer
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:read_single_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:read_single_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:special_characters
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:timespan_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:timespan_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:write_read_multiple_actioned_by_other_pid_allow_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:write_read_multiple_actioned_by_other_pid_deny_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:write_single_allow
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests:write_single_deny
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_forever
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_session
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_timespan
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_forever
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_session
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_timespan
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_allow_forever
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_allow_session
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_allow_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_allow_timespan
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_deny_forever
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_deny_session
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_deny_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:camera_deny_timespan
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_allow_forever
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_allow_session
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_allow_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_allow_timespan
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_deny_forever
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_deny_session
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_deny_single
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke:home_deny_timespan
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-25.10-64:tests/main/interfaces-requests-activates-handlers
  • openstack:ubuntu-25.10-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:audio_record_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:audio_record_timespan_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:audio_record_timespan_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_multiple_actioned_by_other_pid_always_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_multiple_actioned_by_other_pid_always_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_multiple_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_multiple_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_multiple_not_actioned_by_other_pid_single_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_multiple_not_actioned_by_other_pid_single_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_write_chmod_same_fd_single_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_write_chmod_same_path_single_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:create_write_write_same_path_single_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:download_file_conflict
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:download_file_defaults
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:download_file_safer
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:read_single_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:read_single_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:special_characters
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:timespan_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:timespan_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:write_read_multiple_actioned_by_other_pid_allow_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:write_read_multiple_actioned_by_other_pid_deny_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:write_single_allow
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests:write_single_deny
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_forever
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_session
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_allow_timespan
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_forever
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_session
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:audiorecord_deny_timespan
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_allow_forever
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_allow_session
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_allow_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_allow_timespan
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_deny_forever
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_deny_session
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_deny_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:camera_deny_timespan
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_allow_forever
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_allow_session
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_allow_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_allow_timespan
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_deny_forever
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_deny_session
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_deny_single
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke:home_deny_timespan
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-26.04-64:tests/main/i18n
  • openstack:ubuntu-26.04-64:tests/main/interfaces-requests-activates-handlers
  • openstack:ubuntu-26.04-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-core-18-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-core-20-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-core-22-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-core-24-64:tests/main/snapctl-no-wait
  • openstack:ubuntu-core-26-64:tests/main/snapctl-no-wait

@andrewphelpsj andrewphelpsj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments

Comment thread tests/main/snap-tasks/tasks.yaml Outdated

# Check that valid JSON output is produced for the change, and that it contains the expected task with the expected state.
echo "Check that 'snap tasks' lists the task for the change (and accepts the --format option)"
snap tasks --format json "$CHANGE_ID_1" | jq -e '.[0].id == "remove+comp1" and .[0].state == "done"' > /dev/null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this check will pass as written right now, tasks isn't an array.

Comment thread cmd/snap/cmd_changes.go Outdated
@Rnfudge02
Rnfudge02 requested a review from andrewphelpsj May 21, 2026 19:22
@Rnfudge02

Copy link
Copy Markdown
Contributor Author

needs rebase

@andrewphelpsj andrewphelpsj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think your spread test needs some changes. Otherwise, this is close. But I do think it'd be good to assess doing some copy-pasting of that formatMixin.

Comment thread tests/main/snap-tasks/tasks.yaml Outdated

execute: |
echo "Install component to trigger a change"
snap install test-snap-with-components+comp1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple things:

  • comp1 isn't a component for this snap, it seems
  • We should probably just create a change for an installation from file, as to not depend on the store when we don't need to.

In this case, probably don't even need to use a component in this test.

Comment thread tests/main/snap-tasks/tasks.yaml Outdated

# Check that valid JSON output is produced for the change, and that it contains the expected task with the expected state.
echo "Check that 'snap tasks' lists the task for the change (and accepts the --format option)"
snap tasks --format json "$CHANGE_ID_1" | jq -e '.tasks | any(.id == "remove+comp1" and (.status == "Done" or .status == "done" or .state == "done"))' > /dev/null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.id == "remove+comp1" isn't correct, I don't think. Task IDs are numbers.

Comment thread tests/main/snap-tasks/tasks.yaml Outdated
Comment on lines +11 to +13
restore: |
snap remove --purge test-snap-tasks || true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
restore: |
snap remove --purge test-snap-tasks || true

Comment thread cmd/snap/cmd_changes.go Outdated
return err
}

if c.Format == "json" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to just take the formatMixin from pebble, then it'll be easier to stay aligned with them.

@andrewphelpsj andrewphelpsj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM, but I expect that your spread test isn't passing right now. You'll need to address that before merging.

Comment thread tests/main/snap-tasks/task.yaml Outdated

# Check that valid JSON output is produced for the change, and that it contains the expected task with the expected state.
echo "Check that 'snap tasks' lists the task for the change (and accepts the --format option)"
snap tasks --format json "$CHANGE_ID" | jq -e '.tasks | any(.id == "$CHANGE_ID" and (.status == "Done" or .status == "done" or .state == "done"))' > /dev/null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This jq assertion won't work because $CHANGE_ID won't expand, as the expression is inside of single quotes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please use gojq like the other spread tests.

Comment thread cmd/snap/cmd_changes_test.go Outdated
c.Assert(err, check.ErrorMatches, ".*Invalid value `' for option `--format'. Allowed values are: .* or json")
_, err = snap.Parser(snap.Client()).ParseArgs([]string{"tasks", "--format=random", "42"})
c.Assert(err, check.ErrorMatches, ".*Invalid value `random' for option `--format'. Allowed values are: .* or json")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline needed here

@Rnfudge02
Rnfudge02 merged commit 0fc3111 into canonical:master Jun 2, 2026
395 of 415 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Documentation -auto- Label automatically added which indicates the change needs documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants